from rest_framework.filters import BaseFilterBackend


class TalksFilterBackend(BaseFilterBackend):  # BaseFilterBackend的子类必须实现filter_queryset()方法
    """
        数据过滤器
    """

    def filter_queryset(self, request, queryset, view):
        """
        过来源数据
        :param request:
        :param queryset:
        :param view:
        :return:
        """
        mood_id = int(request.query_params.get('mood', 0))  # 获取get参数值
        if mood_id:
            queryset = queryset.filter(mood_id=int(mood_id)).distinct()
        return queryset
